<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PRODUCT ADJUST</title>

<script type="text/javascript">
    $().ready(function() {    
    	view(1);
        $("#onWrite").bind("click",function(){
            location="/productAdjustWrite.html";            
        });
        /* 조회버튼 */
        $("#btnSearch").bind("click",function(){       
            view(1);
        });
        
    });

    function view(page){
        $.post(
                '/getProductAdjustView.json', {                      
                paging : page,//odrNo,
                listScale : "15",
                goodsCode : $("#goodsCode").val(),
                batchNo : $("#batchNo").val(),
                mawb : $("#mawb").val(),
                hawb : $("#hawb").val()
               },
            function(data) {
                //$("#productDetail").remove();
                //reSetValidete(); //벨류데이션 초기화
                searchDataMaping(data);    //DATA맵핑 
            });
    }
    
    /* searchData 맵핑 */
    function searchDataMaping(data){
           
        var contents = "";
        var cHeader = "<tr>"
        	+"<th width='*'>Code</th>"
        	+"<th width='200px'>Product</th>"
        	+"<th width='50px'>MAWB</th>"
        	+"<th width='50px'>HAWB</th>"
        	+"<th width='100px'>BATCH_NO</th>"                        
        	+"<th width='100px'>QTY</th>"
        	+"<th width='200px'>ADJUST_DATE</th>"
        	+"<th width='20px'>U</th>"
        	+"<th width='20px'>D</th>"
        	+"</tr>";
        //$("#productDetail tr").remove();
        if(data.resultList.length == 0){
        	contents = "<tr><td colspan='9' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
            $("#productAdjustDetail").html(cHeader+contents);
            
        }else{
        	$.each(data.resultList, function(index){  // List로 받아온값 (여러건)  
        		
                contents += "<tr style='cursor:pointer' onclick='rowSelect(this, \""+this.adjustNo+"\")'><td align='center'>"+this.goodsCode+"</td>"
                    +"<td align='left' class='boSub'>"+this.goodsName+"</a></td>"
                    +"<td align='center'>"+this.mawb+"</td>"
                    +"<td align='right' class='boSubR'>"+this.hawb+"</td>"
                    +"<td align='center'>"+this.batchNo+"</td>"
                    +"<td align='center'>"+this.qty+"</td>"
                    +"<td align='left' class='boSub'>"+this.adjustDate+"</td>"
                    +"<td align='center'><a href='javascript:onUpdate(\""+this.adjustNo+"\");'><img src='images/web/ic_up.gif' alt='Update' id='onUpdate'/></a></td>"
                    +"<td align='center'><a href='javascript:onDel(\""+this.adjustNo+"\");'><img src='images/web/ic_x.gif' alt='Delete' id='onDelete'/></a></td>"
                    +"</tr>";
             });
        }        
        var totalPage = Math.ceil(parseInt(data.productAdjustCount)/parseInt(15));        
        $("#spanCount").empty().html("Total : "+data.productAdjustCount);
        $("#pageCount").empty().html("Page : "+$("#pageNum").val()+" / "+totalPage);                    
        $("#page").empty().html(data.pageSplit);
        $("#productAdjustDetail").html(cHeader+contents);  // 조회 값 뿌리기
        
    }
    
    function onUpdate(arg){
        location="/productAdjustUpdate.html?adjustNo="+arg;
    }

    function onDetail(arg){
        location="/productAdjustDetail.html?adjustNo="+arg;
    }

    function onDel(arg){
        $.post(
                '/delProductAdjust.json', {  
                	adjustNo : arg
               },
            function(data) {
               if(data.result == true){
                   alert("Deleted.....!");
                   view($("#pageNum").val());    
               }else{
                   alert("ERROR!");
               }  
            });
    }

    function ajaxPageSplit(num) {
        $("#pageNum").val(num);
        view(num);
    }
    
    var goodsCodeTmp = "";
    function rowSelect(obj, goodsCode){
    	goodsCodeTmp = goodsCode;
        $("#productAdjustDetail tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";  
        document.ondblclick=dblclick;
    }

    function dblclick(){
        onUpdate(goodsCodeTmp);
    }
    
    /************************************************************************/
    /*                      상품 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    /* 상품 팝업 버튼 */
    function onProductPopup(obj){
        
        window.open('/productPop.html', 'changeProductPop', 'width=615, height=450, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }

    function productPopValue(goodsCode, goodsName, unit, boxQty, hsCode, productCode, custCode, custName){

        $("#goodsCode").val(goodsCode);
        $("#goodsName").val(goodsName);   
    }
</script>
</head>
<body>
<div class="wrap">
    <div class="pagetitle">
        <h1>PRODUCT ADJUST</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th>Product</th>
                <td>
                    <input type="text" class="inST80" name="goodsName" id="goodsName"/>
                    <img src='/images/web/bkn_zoom.gif' aligh='right' id='stockOutPop' onclick='onProductPopup(this);'>
                    <input type="hidden" class="inST80" name="goodsCode" id="goodsCode"/>
                </td>
                <th>Batch No.</th>
                <td>
                    <input type="text" class="inST80" name="batchNo" id="batchNo"/>
                </td>
            </tr>
            <tr>
                <th>MAWB</th>
                <td>
                    <input type="text" class="inST80" name="mawb" id="mawb"/>
                </td>
                <th>HAWB</th>
                <td>
                    <input type="text" class="inST80" name="hawb" id="hawb"/>
                </td>
            </tr>
            <!-- tr>
                <th>Nation</th>
                <td colspan="3">
                    <input type="text" class="inST" name="nation" id="nation"/>

                </td>
            </tr-->
        </table>
        <div class="bo_btnS">
            <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
        </div>
        <br/><br/><br/><br/>
        <ul>
            <li class="totaltext"><span id="spanCount">Total : 0</span></li>
            <li class="pagetext"><span id="pageCount">Page : 1&frasl;1</span></li>
            <li class="bolistW">
                <table class="TableST4" id="productAdjustDetail">
                    <!-- tr>
                        <th width="100px">Code</th>
                        <th width="*">Product</th>
                        <th width="50">Unit</th>
                        <th width="50px">Box</th>
                        <th width="100px">H.S Code</th>                        
                        <th width="100px">Product Code</th>
                        <th width="150px">Shipper</th>
                        <th width="20px">U</th>
                        <th width="20px">D</th>
                    </tr>
                    <span id="productDetail">
                        <tr>
                           <td colspan="9"></td>    
                        </tr>
                    </span-->                    
                </table>
            </li>
        </ul>
    </div>
    <!--<div class="padeNum">
    <a href="#"><img src="images/web/icon_navi_01.gif" /></a>1.2.3.4.5.6.7<a href="#"><img src="images/web/icon_navi_02.gif" /></a>
    </div>
    -->
    <div class="page_wrap">
        <div class="page" id="page" >
        </div>
    </div>
    <div class="bo_btn">
        <ul class="btnst"><li class="a"><a href="#" id="onWrite" >INSERT</a></li></ul>
    </div>
    <input type="hidden" name="pageNum" id="pageNum" value="1">
</div>
</body>
</html>